/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cmp.arena.controls;

import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.Control;

/**
 * Counts the time for the match and sets related flags.
 * @author krummer
 */
public class TimeControl extends AbstractControl {
    private float playtime;
    
    @Override
    public void setSpatial(Spatial spatial) {
        super.setSpatial(spatial);
        this.playtime = 600.f; //default value
        spatial.setUserData("matchTime", this.playtime);
    }

    @Override
    protected void controlUpdate(float tpf) {
        this.setMatchTime(this.getMatchTime() - tpf);
        if(this.getMatchTime() < 0.f) {
            this.setMatchTime(0.f);
        }
    }

    @Override
    protected void controlRender(RenderManager rm, ViewPort vp) {
    }
    
    public float getMatchTime() {
        return super.getSpatial().getUserData("matchTime");
    }
    
    public void setMatchTime(float time) {
        super.getSpatial().setUserData("matchTime", time);
    }
    
    public void setPlayTime(float time) {
        this.playtime = time;
    }

    public Control cloneForSpatial(Spatial spatial) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
